<?php
/**
 * @name TestModel
 * 本应该写在 模块下的
 */
class TestModel {
	/**
	 * @var \Medoo\Medoo
	 */
	private $db;
	private $table = 'article';
    public function __construct() {
	    $this->db = \Yaf\Registry::get('db');
    }
    
    public function list($page=1, $max=10) {
    	$count=$this->db->count($this->table, '*');
    	$list=[];
    	if($count>0){
    		$list=$this->db->select($this->table, "*", ['LIMIT' => [($page-1)*$max, $max],]);
	    }
	    return [$count, $list];
    }
	public function get($id){
		return $this->db->get($this->table, "*", ['id'=>$id]);
	}
	public function update($id, $data){
		return $this->db->update($this->table, $data, ['id'=>$id]);
	}
	public function create($data){
		$ok=$this->db->insert($this->table, $data);
		return $ok?$this->db->id():false;
	}
	public function delete($id){
		return $this->db->delete($this->table, ['id'=>$id]);
	}
}
